package org.myspringframework.context.annotation;

import org.myspringframework.beans.factory.config.beandefinition.BeanDefinition;
import org.myspringframework.context.annotation.Component;
import org.myspringframework.utils.ClassUtils;

import java.util.LinkedHashSet;
import java.util.Set;

//通过basePackage扫描带Components注解的class
public class ClassPathScanningCandidateComponentProvider {

    //扫描包下带@Component注解的类
    public Set<BeanDefinition> findCandidateComponents(String basePackage) {
        Set<BeanDefinition> candidates = new LinkedHashSet<>();
        Set<Class<?>> classes = ClassUtils.scanPackageByAnnotation(basePackage, Component.class);
        for (Class<?> clazz : classes) {
            //添加相应的beanDefinition
            candidates.add(new BeanDefinition(clazz));
        }
        return candidates;
    }

}